package com.kefu.chat.smart.condition;

import java.util.List;
import java.util.Map;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.kefu.chat.smart.ChatConnectCondition;
import com.kefu.chat.vo.ChatUserParam.UserConnectP;
import com.kefu.chat.vo.ChatUserParam.UserConnectR;
import com.kefu.common.trigger.Condition;
import com.kefu.common.trigger.Decision;
import com.kefu.common.trigger.TriggerWrapper;
import com.kefu.common.trigger.model.ConditionModel;
import com.kefu.common.trigger.model.DynamicModel;
import com.kefu.common.trigger.model.DynamicModel.OptionType;
import com.kefu.common.trigger.model.DynamicModel.SearchType;

//@Component
public class ChatLastAdminCondition implements ChatConnectCondition<Integer> {

	@Override
	public String getCode() {
		return "last_admin_id";
	}

	@Override
	public ConditionModel getConditionModel() {
		Map<String,String> groupSearch=Maps.newHashMap();
		 groupSearch.put("groupType", "0");
		 
		return ConditionModel.builder()
				.code(getCode())
				.name(getMessageName())
				.decisions(Lists.newArrayList(Decision.IS_NOT_NULL,Decision.IS_NULL,Decision.EQ))
				.optionType(OptionType.Simple)
				.dynamicModel(DynamicModel.<ConditionModel>builder()
						.url("sys/user/searchUserByGroupType")
						.searchType(SearchType.Page)
						.code("userId")
						.name("userName")
						.params(groupSearch)
						.build())
				.build();
	}

	@Override
	public String getName() {
		return "最后连接人";
	}

	@Override
	public boolean match(TriggerWrapper<UserConnectP, UserConnectR> wrapper, Condition condition) {
		List<Integer> list=getOperatorList(condition,(c)->Integer.parseInt(c));
		return getCustomer(wrapper)!=null&&condition.getDecision().match(list, getChatUser(wrapper).getChannelType(),null);
	}

}
